
Namespace Validation

    Public Class Validator
        Implements IValidationRuleMethod

#Region " Declarations "

        Private _enumRuleType As RuleType = RuleType.Attribute
        Private _objRuleEventArgs As RuleEventArgs
        Private _objRuleHandler As RuleHandler
        Private _strRuleName As String = String.Empty

#End Region

#Region " Properties "

        Public ReadOnly Property RuleEventArgs() As RuleEventArgs Implements IValidationRuleMethod.RuleEventArgs
            Get
                Return _objRuleEventArgs
            End Get
        End Property

        Public ReadOnly Property RuleName() As String Implements IValidationRuleMethod.RuleName
            Get
                Return _strRuleName
            End Get
        End Property

        Public ReadOnly Property RuleType() As RuleType
            Get
                Return _enumRuleType
            End Get
        End Property

#End Region

#Region " Constructor "

        ''' <summary>
        ''' Creates a shared or instance validator
        ''' </summary>
        Public Sub New(ByVal objRuleHandler As RuleHandler, ByVal e As RuleEventArgs, ByVal enumRuleType As RuleType)
            _objRuleEventArgs = e
            _objRuleHandler = objRuleHandler
            _enumRuleType = enumRuleType

            Select Case enumRuleType

                Case RuleType.Instance
                    _strRuleName = "instance" & _strRuleName

                Case RuleType.Shared, RuleType.Attribute
                    _strRuleName = String.Format("rule://{0}/{1}-{2}", objRuleHandler.Method.Name, e.PropertyName, (Guid.NewGuid).ToString)

                Case Else
                    Throw New ArgumentException("RuleType not programmed yet", "RuleType")
            End Select

        End Sub

#End Region

#Region " Methods "

        Public Function Invoke(ByVal target As Object) As Boolean Implements IValidationRuleMethod.Invoke
            Return _objRuleHandler.Invoke(target, _objRuleEventArgs)
        End Function

#End Region

    End Class

End Namespace
